using System.Drawing;
using GTA;
using NativeUI;

namespace CustomPeds.Menus;

public class OnFootMainMenu : Script
{
	public static UIMenu menu = new UIMenu("", TextSetting.of_Menu, new Point(0, -107));
	private static bool isMenuInitialized;

	public OnFootMainMenu()
	{
		if (!isMenuInitialized)
		{
			Main.pool.Add(menu);
			menu.OnItemSelect += OnItemSelect;
			menu.OnMenuClose += OnMenuClose;
			isMenuInitialized = true;
		}
	}

	public static void InitOnFootMainMenu()
	{
		menu.Clear();
		menu.SetBannerType(new UIResRectangle());
		menu.AddItem(new UIMenuItem(TextSetting.of_MenuItem_Chat));
		if (!Main.P1.Character.IsInVehicle() && Main.IsGirlfriendInNear(3f))
		{
			menu.AddItem(new UIMenuItem(TextSetting.of_MenuItem_Special));
			menu.BindMenuToItem(OnFootSexMenu.menu, menu.MenuItems[1]);
		}
		menu.RefreshIndex();
	}

	private void OnIndexChange(UIMenu sender, int index)
	{
	}

	private void OnItemSelect(UIMenu sender, UIMenuItem item, int index)
	{
		switch (index)
		{
		case 0:
			Main.P2.Character.PlayAmbientSpeech1("CHAT_STATE", immediately: true);
			Main.P2.Character.IsSpeechPlayingToEnd();
			Main.P1.Character.PlayAmbientSpeech1("CHAT_RESP", immediately: true);
			break;
		case 1:
			Main.P2.Character.PlayAmbientSpeech2("HOOKER_OFFER_SERVICE", immediately: false);
			Main.P2.Character.IsSpeechPlayingToEnd();
			break;
		}
	}

	private void OnMenuClose(UIMenu sender)
	{
		menu.Visible = false;
		OnFootSexScript.StageEnd();
	}
}
